<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
class media_media_manage extends CI_Controller {
	public function __construct() {
		session_start ();
		parent::__construct ();
		$this->load->helper ( "common" );
	}
	public function index() {
		$this->media_main ();
	}
	public function media_main() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		
		$data ['update_media_draft'] = false;
		if ($this->right_manage->check_right ( "update_media_draft" )) {
			$data ['update_media_draft'] = true;
		}
		$data ['delete_media_draft'] = false;
		if ($this->right_manage->check_right ( "delete_media_draft" )) {
			$data ['delete_media_draft'] = true;
		}
		$data ['add_media_draft'] = false;
		if ($this->right_manage->check_right ( "add_media_draft" )) {
			$data ['add_media_draft'] = true;
		}
		$data ['query_media_draft'] = false;
		if ($this->right_manage->check_right ( "query_media_draft" )) {
			$data ['query_media_draft'] = true;
		}
		$data ['check_media_draft'] = false;
		if ($this->right_manage->check_right ( "check_media_draft" )) {
			$data ['check_media_draft'] = true;
		}
		$data ['query_media'] = false;
		if ($this->right_manage->check_right ( "query_media" )) {
			$data ['query_media'] = true;
		}
		
		$search ['province'] = $this->input->get ( "province" );
		$search ['city'] = $this->input->get ( "city" );
		$search ['region'] = $this->input->get ( "region" );
		$search ['keyword'] = $this->input->get ( "keyword" );
		$search ['media_type'] = $this->input->get ( "media_type" );
		$search ['media_type_id'] = $this->input->get ( "media_type_id" );
		
		$this->load->library ( "media/media" );
		$data ['media_draft_list'] = $this->media->query_my_media_draft_list ( $_SESSION ['user_name'], $_SESSION ['user_id'], $search );
		$data ['num'] = $this->media->query_my_media_draft_num ( $_SESSION ['user_name'], $_SESSION ['user_id'], $search );
		
		$this->load->library ( "sys/media_type" );
		$data ['media_type_list'] = $this->media_type->get_all_media_type ();
		
		$this->load->library ( "sys/region" );
		$data ['province_list'] = $this->region->query_user_top_regions ( $_SESSION ['user_id'] );
		$data ['city_list'] = null;
		$data ['region_list'] = null;
		if ($search ['province']) {
			$data ['city_list'] = $this->region->get_regions ( $search ['province'] );
		}
		if ($search ['city']) {
			$data ['region_list'] = $this->region->get_regions ( $search ['city'] );
		}
		
		$data ['search'] = $search;
		$search_url = format_search_url ( $search );
		
		$this->load->library ( "tools/pagination" );
		$data ['page_link'] = $this->pagination->get_pagination ( base_url () . "index.php/media_media_manage?$search_url", $data ['num'] );
		$this->load->view ( "media/media/media_main", $data );
	}
	public function add_media_draft() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "add_media_draft", $_SESSION ['user_id'] )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$media_type = $this->input->get ( "media_type" );
		$this->load->library ( "sys/region" );
		$data ['top_regions'] = $this->region->query_user_top_regions ( $_SESSION ['user_id'] );
		
		$this->load->library ( "sys/media_type" );
		$data ['media_type_list'] = $this->media_type->get_all_media_type ();
		$this->load->library ( "sys/crafts" );
		$data ['crafts_list'] = $this->crafts->get_all_crafts ();
		$this->load->library ( "sys/corner_case" );
		$data ['corner_case_list'] = $this->corner_case->get_all_corner_case ();
		$this->load->library ( "sys/media_area" );
		$data ['media_area_list'] = $this->media_area->get_all_media_area ();
		
		if ($media_type == "airport" || $media_type == "airport_led") {
			$data ['media_type'] = $media_type;
			$this->load->library ( "env/env_airport" );
			$data ['airport_list'] = $this->env_airport->get_all_airport ();
			$this->load->view ( "media/media/add_media_airport", $data );
		} elseif ($media_type == "highway") {
			$data ['media_type'] = "highway";
			$this->load->library ( "env/env_highway" );
			$data ['highway_list'] = $this->env_highway->get_all_highway ();
			$this->load->view ( "media/media/add_media_highway", $data );
		} elseif ($media_type == "led") {
			$data ['media_type'] = "led";
			$this->load->view ( "media/media/add_media_urban", $data );
		} else {
			$data ['media_type'] = "common";
			$this->load->view ( "media/media/add_media_urban", $data );
		}
	}
	public function save_media_draft() {
		$this->load->library ( "common/login_manage" );
		if ($this->login_manage->check_login () == false) {
			$data ['result'] = false;
			$data ['message'] = '请您先登录';
			echo json_encode ( $data );
			die ();
		}
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "add_media_draft", $_SESSION ['user_id'] )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			echo json_encode ( $data );
			die ();
		}
		
		$media ['media_type'] = $this->input->post ( "media_type" );
		$media ['province'] = $this->input->post ( "province" );
		$media ['city'] = $this->input->post ( "city" );
		$media ['region'] = $this->input->post ( "region" );
		$media ['location'] = $this->input->post ( "location" );
		$media ['vendor'] = $this->input->post ( "vendor" );
		$media ['media_type_id'] = $this->input->post ( "media_type_id" );
		$media ['crafts'] = $this->input->post ( "crafts" );
		$media ['corner_case'] = $this->input->post ( "corner_case" );
		$media ['illumination'] = $this->input->post ( "illumination" );
		$media ['flow'] = $this->input->post ( "flow" );
		$media ['media_area'] = trim ( $this->input->post ( "media_area" ) );
		$media ['reference_price'] = trim ( $this->input->post ( "reference_price" ) );
		$media ['sketch_map'] = trim ( $this->input->post ( "sketch_map" ) );
		$media ['longitude'] = $this->input->post ( "longitude" );
		$media ['latitude'] = $this->input->post ( "latitude" );
		$media ['specification_width'] = $this->input->post ( "specification_width" );
		$media ['specification_height'] = $this->input->post ( "specification_height" );
		$media ['quote'] = $this->input->post ( "quote" );
		$media ['unique_id'] = $this->input->post ( "unique_id" );
		$media ['media_draft_type'] = $this->input->post ( "media_draft_type" );
		$media ['agreement'] = $this->input->post ( "agreement" );
		$media ['price_remark'] = $this->input->post ( "price_remark" );
		
		$media ['play_time'] = $this->input->post ( "play_time" );
		$media ['play_time_remark'] = $this->input->post ( "play_time_remark" );
		$media ['play_format'] = $this->input->post ( "play_format" );
		$media ['play_frequency'] = $this->input->post ( "play_frequency" );
		$media ['play_frequency_remark'] = $this->input->post ( "play_frequency_remark" );
		$media ['resolution'] = $this->input->post ( "resolution" );
		
		$media ['create_by'] = $_SESSION ['user_name'];
		$media ['create_time'] = date ( "Y-m-d H:i:s" );
		
		$urban_env ['circle'] = $this->input->post ( "circle" );
		$urban_env ['road'] = $this->input->post ( "road" );
		$urban_env ['market'] = $this->input->post ( "market" );
		$urban_env ['station'] = $this->input->post ( "station" );
		$urban_env ['stop'] = $this->input->post ( "stop" );
		$urban_env ['venues'] = $this->input->post ( "venues" );
		$urban_env ['cbd'] = $this->input->post ( "cbd" );
		$urban_env ['chief_district'] = $this->input->post ( "chief_district" );
		$urban_env ['industrial'] = $this->input->post ( "industrial" );
		
		$media ['highway_id'] = $this->input->post ( "highway_id" );
		$media ['section_id'] = $this->input->post ( "section_id" );
		$media ['point_id'] = $this->input->post ( "point_id" );
		
		$media ['airport_id'] = $this->input->post ( "airport_id" );
		
		$pic = $this->input->post ( "pic" );
		$explanation = $this->input->post ( "explanation" );
		$this->load->library ( "media/media" );
		$result = $this->media->save_media_draft ( $media, $urban_env, $explanation, $pic );
		$this->load->helper ( "common" );
		echo JSON ( $result );
	}
	public function edit_media_draft() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "update_media_draft", $_SESSION ['user_id'] )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$this->load->library ( "media/media" );
		$media_draft_id = $this->input->get ( "media_draft_id" );
		$data ['media_draft_info'] = $this->media->query_media_draft ( $media_draft_id );
		
		if (! $data ['media_draft_info']) {
			$data ['title'] = "编辑媒体草稿失败";
			$data ['message'] = "没有找到你要编辑的媒体草稿信息。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		$data ['media_pic_list'] = $this->media->query_media_draft_pic_list ( $media_draft_id );
		
		$this->load->library ( "sys/media_type" );
		$data ['media_type_list'] = $this->media_type->get_all_media_type ();
		$this->load->library ( "sys/crafts" );
		$data ['crafts_list'] = $this->crafts->get_all_crafts ();
		$this->load->library ( "sys/corner_case" );
		$data ['corner_case_list'] = $this->corner_case->get_all_corner_case ();
		$this->load->library ( "sys/media_area" );
		$data ['media_area_list'] = $this->media_area->get_all_media_area ();
		// 区域
		$this->load->library ( "sys/region" );
		$data ['top_regions'] = $this->region->query_user_top_regions ( $_SESSION ['user_id'] );
		$data ['second_regions'] = null;
		$data ['last_regions'] = null;
		if ($data ['media_draft_info'] ['city']) {
			$data ['second_regions'] = $this->region->get_regions ( $data ['media_draft_info'] ['province'] );
		}
		if ($data ['media_draft_info'] ['region']) {
			$data ['last_regions'] = $this->region->get_regions ( $data ['media_draft_info'] ['city'] );
		}
		// 供应商
		$this->load->library ( "ven/vendor" );
		$data ['vendor_list'] = $this->vendor->get_vendors ( $data ['media_draft_info'] ['region'] );
		
		if ($data ['media_draft_info'] ['media_type'] == "airport" || $data ['media_draft_info'] ['media_type'] == "airport_led") {
			// 获取机场
			$this->load->library ( "env/env_airport" );
			$data ['airport_list'] = $this->env_airport->get_all_airport ();
			$this->load->view ( "media/media/edit_media_draft_airport", $data );
		} elseif ($data ['media_draft_info'] ['media_type'] == "highway") {
			$this->load->library ( "env/env_highway" );
			$data ['highway_list'] = $this->env_highway->get_all_highway ();
			
			$this->load->library ( "env/highway_section" );
			$data ['section_list'] = $this->highway_section->get_all_section ( $data ['media_draft_info'] ['highway_id'] );
			
			$this->load->library ( "env/highway_point" );
			$data ['point_list'] = $this->highway_point->get_all_point ( $data ['media_draft_info'] ['section_id'] );
			
			$this->load->view ( "media/media/edit_media_draft_highway", $data );
		} else {
			
			$data ['env_list'] = $this->media->query_media_draft_env_list ( $media_draft_id );
			$this->load->library ( "env/urban_circle" );
			$data ['circle_list'] = $this->urban_circle->get_env_list ( "circle", $data ['media_draft_info'] ['region'] );
			$data ['road_list'] = $this->urban_circle->get_env_list ( "road", $data ['media_draft_info'] ['region'] );
			$data ['station_list'] = $this->urban_circle->get_env_list ( "station", $data ['media_draft_info'] ['region'] );
			$data ['market_list'] = $this->urban_circle->get_env_list ( "market", $data ['media_draft_info'] ['region'] );
			$data ['stop_list'] = $this->urban_circle->get_env_list ( "stop", $data ['media_draft_info'] ['region'] );
			$data ['venues_list'] = $this->urban_circle->get_env_list ( "venues", $data ['media_draft_info'] ['region'] );
			$data ['cbd_list'] = $this->urban_circle->get_env_list ( "cbd", $data ['media_draft_info'] ['region'] );
			$data ['chief_district_list'] = $this->urban_circle->get_env_list ( "chief_district", $data ['media_draft_info'] ['region'] );
			$data ['industrial_list'] = $this->urban_circle->get_env_list ( "industrial", $data ['media_draft_info'] ['region'] );
			
			$this->load->view ( "media/media/edit_media_draft_urban", $data );
		}
	}
	public function edit_media_draft_pic() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "update_media_draft", $_SESSION ['user_id'] )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$this->load->library ( "media/media" );
		$media_draft_id = $this->input->get ( "media_draft_id" );
		$data ['media_draft_info'] = $this->media->query_media_draft ( $media_draft_id );
		$data ['media_pic_list'] = $this->media->query_media_draft_pic_list ( $media_draft_id );
		$this->load->view ( "media/media/edit_media_draft_pic", $data );
	}
	public function save_media_draft_pic() {
		$media_draft_id = $this->input->get_post ( "media_draft_id" );
		$this->load->library ( "media/media" );
		$this->media->save_media_draft_pic ( $media_draft_id );
		$data ['status'] = "ok";
		echo json_encode ( $data );
	}
	public function update_media_draft() {
		$this->load->library ( "common/login_manage" );
		if ($this->login_manage->check_login () == false) {
			$data ['result'] = false;
			$data ['message'] = '请您先登录';
			echo json_encode ( $data );
			die ();
		}
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "update_media_draft", $_SESSION ['user_id'] )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			echo json_encode ( $data );
			die ();
		}
		
		$media_draft_id = $this->input->post ( "media_draft_id" );
		$media ['media_type'] = $this->input->post ( "media_type" );
		$media ['province'] = $this->input->post ( "province" );
		$media ['city'] = $this->input->post ( "city" );
		$media ['region'] = $this->input->post ( "region" );
		$media ['location'] = $this->input->post ( "location" );
		$media ['vendor'] = $this->input->post ( "vendor" );
		$media ['media_type_id'] = $this->input->post ( "media_type_id" );
		$media ['crafts'] = $this->input->post ( "crafts" );
		$media ['corner_case'] = $this->input->post ( "corner_case" );
		$media ['illumination'] = $this->input->post ( "illumination" );
		$media ['flow'] = $this->input->post ( "flow" );
		$media ['media_area'] = trim ( $this->input->post ( "media_area" ) );
		$media ['reference_price'] = trim ( $this->input->post ( "reference_price" ) );
		$media ['sketch_map'] = trim ( $this->input->post ( "sketch_map" ) );
		$media ['longitude'] = $this->input->post ( "longitude" );
		$media ['latitude'] = $this->input->post ( "latitude" );
		$media ['specification_width'] = $this->input->post ( "specification_width" );
		$media ['specification_height'] = $this->input->post ( "specification_height" );
		
		$media ['agreement'] = $this->input->post ( "agreement" );
		$media ['price_remark'] = $this->input->post ( "price_remark" );
		
		$media ['play_time'] = $this->input->post ( "play_time" );
		$media ['play_time_remark'] = $this->input->post ( "play_time_remark" );
		$media ['play_format'] = $this->input->post ( "play_format" );
		$media ['play_frequency'] = $this->input->post ( "play_frequency" );
		$media ['play_frequency_remark'] = $this->input->post ( "play_frequency_remark" );
		$media ['resolution'] = $this->input->post ( "resolution" );
		
		$pic = $this->input->post ( "pic" );
		$media ['modify_by'] = $_SESSION ['user_name'];
		$media ['modify_time'] = date ( "Y-m-d H:i:s" );
		
		$urban_env ['circle'] = $this->input->post ( "circle" );
		$urban_env ['road'] = $this->input->post ( "road" );
		$urban_env ['market'] = $this->input->post ( "market" );
		$urban_env ['station'] = $this->input->post ( "station" );
		$urban_env ['stop'] = $this->input->post ( "stop" );
		$urban_env ['venues'] = $this->input->post ( "venues" );
		$urban_env ['cbd'] = $this->input->post ( "cbd" );
		$urban_env ['chief_district'] = $this->input->post ( "chief_district" );
		$urban_env ['industrial'] = $this->input->post ( "industrial" );
		
		$media ['highway_id'] = $this->input->post ( "highway_id" );
		$media ['section_id'] = $this->input->post ( "section_id" );
		$media ['point_id'] = $this->input->post ( "point_id" );
		
		$media ['airport_id'] = $this->input->post ( "airport_id" );
		
		$explanation = $this->input->post ( "explanation" );
		$this->load->library ( "media/media" );
		$result = $this->media->update_media_draft ( $media, $urban_env, $explanation, $pic, $media_draft_id );
		$this->load->helper ( "common" );
		echo JSON ( $result );
	}
	public function delete_media_draft() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "delete_media_draft", $_SESSION ['user_id'] )) {
			$this->load->library ( "common/user_menu" );
			$data ['user_menu'] = $this->user_menu->get_user_menu ();
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$this->load->library ( "media/media" );
		$media_draft_id = intval ( $this->input->get ( 'media_draft_id' ) );
		$this->media->delete_media_draft ( $media_draft_id );
		echo "<script>history.go(-1)</script>";
	}
	public function submit_check_draft() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "add_media_draft" ) && ! $this->right_manage->check_right ( "update_media_draft" )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$this->load->library ( "media/media" );
		$media_draft_id = intval ( $this->input->get ( 'media_draft_id' ) );
		$this->media->submit_check_draft ( $media_draft_id );
		echo "<script>history.go(-1)</script>";
	}
	public function check_list() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "check_media_draft" )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$search ['province'] = $this->input->get ( "province" );
		$search ['city'] = $this->input->get ( "city" );
		$search ['region'] = $this->input->get ( "region" );
		$search ['keyword'] = $this->input->get ( "keyword" );
		$search ['media_type'] = $this->input->get ( "media_type" );
		$search ['media_type_id'] = $this->input->get ( "media_type_id" );
		
		$this->load->library ( "media/media" );
		$data ['media_draft_list'] = $this->media->query_check_media_draft_list ( $_SESSION ['user_id'], $search );
		$data ['num'] = $this->media->query_check_media_draft_num ( $_SESSION ['user_id'], $search );
		
		$this->load->library ( "sys/media_type" );
		$data ['media_type_list'] = $this->media_type->get_all_media_type ();
		
		$this->load->library ( "sys/region" );
		$data ['province_list'] = $this->region->query_user_top_regions ( $_SESSION ['user_id'] );
		$data ['city_list'] = null;
		$data ['region_list'] = null;
		if ($search ['province']) {
			$data ['city_list'] = $this->region->get_regions ( $search ['province'] );
		}
		if ($search ['city']) {
			$data ['region_list'] = $this->region->get_regions ( $search ['city'] );
		}
		
		$data ['search'] = $search;
		$search_url = format_search_url ( $search );
		
		$this->load->library ( "tools/pagination" );
		$data ['page_link'] = $this->pagination->get_pagination ( base_url () . "index.php/media_media_manage/check_list?$search_url", $data ['num'] );
		$this->load->view ( "media/media/check_list", $data );
	}
	public function check_media_draft() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "check_media_draft" )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$this->load->library ( "media/media" );
		$media_draft_id = $this->input->get ( "media_draft_id" );
		$data ['media_draft_info'] = $this->media->query_media_draft_detail ( $media_draft_id );
		if (! $data ['media_draft_info']) {
			$data ['title'] = "审核媒体草稿失败";
			$data ['message'] = "没有找到你要审核的媒体草稿信息。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		$data ['media_pic_list'] = $this->media->query_media_draft_pic_list ( $media_draft_id );
		
		if ($data ['media_draft_info'] ['media_type'] == "airport") {
			// 获取机场
			$this->load->library ( "env/env_airport" );
			$data ['airport_list'] = $this->env_airport->get_all_airport ();
		} elseif ($data ['media_draft_info'] ['media_type'] == "highway") {
			$this->load->library ( "env/env_highway" );
			$data ['highway_list'] = $this->env_highway->get_all_highway ();
			
			$this->load->library ( "env/highway_section" );
			$data ['section_list'] = $this->highway_section->get_all_section ( $data ['media_draft_info'] ['highway_id'] );
			
			$this->load->library ( "env/highway_point" );
			$data ['point_list'] = $this->highway_point->get_all_point ( $data ['media_draft_info'] ['section_id'] );
		} else {
			$data ['env_list'] = $this->media->query_media_draft_env_list ( $media_draft_id );
			$this->load->library ( "env/urban_circle" );
			$data ['circle_list'] = $this->urban_circle->get_env_list ( "circle", $data ['media_draft_info'] ['region'] );
			$data ['road_list'] = $this->urban_circle->get_env_list ( "road", $data ['media_draft_info'] ['region'] );
			$data ['station_list'] = $this->urban_circle->get_env_list ( "station", $data ['media_draft_info'] ['region'] );
			$data ['market_list'] = $this->urban_circle->get_env_list ( "market", $data ['media_draft_info'] ['region'] );
			$data ['stop_list'] = $this->urban_circle->get_env_list ( "stop", $data ['media_draft_info'] ['region'] );
			$data ['venues_list'] = $this->urban_circle->get_env_list ( "venues", $data ['media_draft_info'] ['region'] );
			$data ['cbd_list'] = $this->urban_circle->get_env_list ( "cbd", $data ['media_draft_info'] ['region'] );
			$data ['chief_district_list'] = $this->urban_circle->get_env_list ( "chief_district", $data ['media_draft_info'] ['region'] );
			$data ['industrial_list'] = $this->urban_circle->get_env_list ( "industrial", $data ['media_draft_info'] ['region'] );
		}
		$this->load->library ( "media/media_draft_log" );
		$data ['logs'] = $this->media_draft_log->get_logs ( $media_draft_id );
		$this->load->view ( "media/media/check_media_draft", $data );
	}
	public function allow_media() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "check_media_draft" )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$media_draft_id = $this->input->get ( "media_draft_id" );
		$this->load->library ( "media/media" );
		$this->media->allow_media ( $media_draft_id );
		
		redirect ( base_url () . "index.php/media_media_manage/check_list" );
	}
	public function not_allow_draft() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "check_media_draft" )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$media_draft_id = $this->input->get_post ( "media_draft_id" );
		$explanation = trim ( $this->input->get_post ( "explanation" ) );
		$this->load->library ( "media/media" );
		$this->media->not_allow_draft ( $media_draft_id, $explanation );
		
		redirect ( base_url () . "index.php/media_media_manage/check_list" );
	}
	public function media_list() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "query_media" )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$search ['province'] = $this->input->get ( "province" );
		$search ['city'] = $this->input->get ( "city" );
		$search ['region'] = $this->input->get ( "region" );
		$search ['keyword'] = $this->input->get ( "keyword" );
		$search ['media_type'] = $this->input->get ( "media_type" );
		$search ['media_type_id'] = $this->input->get ( "media_type_id" );
		
		$this->load->library ( "media/media" );
		$data ['media_list'] = $this->media->query_media_list ( $_SESSION ['user_id'], $search );
		$data ['num'] = $this->media->query_media_num ( $_SESSION ['user_id'], $search );
		
		$this->load->library ( "sys/media_type" );
		$data ['media_type_list'] = $this->media_type->get_all_media_type ();
		
		$this->load->library ( "sys/region" );
		$data ['province_list'] = $this->region->query_user_top_regions ( $_SESSION ['user_id'] );
		$data ['city_list'] = null;
		$data ['region_list'] = null;
		if ($search ['province']) {
			$data ['city_list'] = $this->region->get_regions ( $search ['province'] );
		}
		if ($search ['city']) {
			$data ['region_list'] = $this->region->get_regions ( $search ['city'] );
		}
		
		$data ['search'] = $search;
		$search_url = format_search_url ( $search );
		
		$this->load->library ( "tools/pagination" );
		$data ['page_link'] = $this->pagination->get_pagination ( base_url () . "index.php/media_media_manage/media_list?$search_url", $data ['num'] );
		$this->load->view ( "media/media/media_list", $data );
	}
	public function edit_media() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "update_media_draft" )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$this->load->library ( "media/media" );
		$media_id = $this->input->get ( "media_id" );
		$data ['media_info'] = $this->media->query_media ( $media_id );
		$data ['media_pic_list'] = $this->media->query_media_pic_list ( $media_id );
		
		$this->load->library ( "sys/media_type" );
		$data ['media_type_list'] = $this->media_type->get_all_media_type ();
		$this->load->library ( "sys/crafts" );
		$data ['crafts_list'] = $this->crafts->get_all_crafts ();
		$this->load->library ( "sys/corner_case" );
		$data ['corner_case_list'] = $this->corner_case->get_all_corner_case ();
		$this->load->library ( "sys/media_area" );
		$data ['media_area_list'] = $this->media_area->get_all_media_area ();
		// 区域
		$this->load->library ( "sys/region" );
		$data ['top_regions'] = $this->region->query_user_top_regions ( $_SESSION ['user_id'] );
		$data ['second_regions'] = null;
		$data ['last_regions'] = null;
		if ($data ['media_info'] ['city']) {
			$data ['second_regions'] = $this->region->get_regions ( $data ['media_info'] ['province'] );
		}
		if ($data ['media_info'] ['region']) {
			$data ['last_regions'] = $this->region->get_regions ( $data ['media_info'] ['city'] );
		}
		// 供应商
		$this->load->library ( "ven/vendor" );
		$data ['vendor_list'] = $this->vendor->get_vendors ( $data ['media_info'] ['region'] );
		
		if ($data ['media_info'] ['media_type'] == "airport" || $data ['media_info'] ['media_type'] == "airport_led") {
			// 获取机场
			$this->load->library ( "env/env_airport" );
			$data ['airport_list'] = $this->env_airport->get_all_airport ();
			$this->load->view ( "media/media/edit_media_airport", $data );
		} elseif ($data ['media_info'] ['media_type'] == "highway") {
			$this->load->library ( "env/env_highway" );
			$data ['highway_list'] = $this->env_highway->get_all_highway ();
			
			$this->load->library ( "env/highway_section" );
			$data ['section_list'] = $this->highway_section->get_all_section ( $data ['media_info'] ['highway_id'] );
			
			$this->load->library ( "env/highway_point" );
			$data ['point_list'] = $this->highway_point->get_all_point ( $data ['media_info'] ['section_id'] );
			
			$this->load->view ( "media/media/edit_media_highway", $data );
		} else {
			$data ['env_list'] = $this->media->query_media_env_list ( $media_id );
			$this->load->library ( "env/urban_circle" );
			$data ['circle_list'] = $this->urban_circle->get_env_list ( "circle", $data ['media_info'] ['region'] );
			$data ['road_list'] = $this->urban_circle->get_env_list ( "road", $data ['media_info'] ['region'] );
			$data ['station_list'] = $this->urban_circle->get_env_list ( "station", $data ['media_info'] ['region'] );
			$data ['market_list'] = $this->urban_circle->get_env_list ( "market", $data ['media_info'] ['region'] );
			$data ['stop_list'] = $this->urban_circle->get_env_list ( "stop", $data ['media_info'] ['region'] );
			$data ['venues_list'] = $this->urban_circle->get_env_list ( "venues", $data ['media_info'] ['region'] );
			$data ['cbd_list'] = $this->urban_circle->get_env_list ( "cbd", $data ['media_info'] ['region'] );
			$data ['chief_district_list'] = $this->urban_circle->get_env_list ( "chief_district", $data ['media_info'] ['region'] );
			$data ['industrial_list'] = $this->urban_circle->get_env_list ( "industrial", $data ['media_info'] ['region'] );
			
			$this->load->view ( "media/media/edit_media_urban", $data );
		}
	}
	public function get_media_draft() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "query_media_draft" )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$this->load->library ( "media/media" );
		$media_draft_id = $this->input->get ( "media_draft_id" );
		$data ['media_draft_info'] = $this->media->query_media_draft_detail ( $media_draft_id );
		if (! $data ['media_draft_info']) {
			$data ['title'] = "查看媒体草稿失败";
			$data ['message'] = "没有找到你要查看的媒体草稿信息。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$data ['media_pic_list'] = $this->media->query_media_draft_pic_list ( $media_draft_id );
		
		if ($data ['media_draft_info'] ['media_type'] == "airport" || $data ['media_draft_info'] ['media_type'] == "airport_led") {
			// 获取机场
			$this->load->library ( "env/env_airport" );
			$data ['airport_list'] = $this->env_airport->get_all_airport ();
		} elseif ($data ['media_draft_info'] ['media_type'] == "highway") {
			$this->load->library ( "env/env_highway" );
			$data ['highway_list'] = $this->env_highway->get_all_highway ();
			
			$this->load->library ( "env/highway_section" );
			$data ['section_list'] = $this->highway_section->get_all_section ( $data ['media_draft_info'] ['highway_id'] );
			
			$this->load->library ( "env/highway_point" );
			$data ['point_list'] = $this->highway_point->get_all_point ( $data ['media_draft_info'] ['section_id'] );
		} else {
			$data ['env_list'] = $this->media->query_media_draft_env_list ( $media_draft_id );
			$this->load->library ( "env/urban_circle" );
			$data ['circle_list'] = $this->urban_circle->get_env_list ( "circle", $data ['media_draft_info'] ['region'] );
			$data ['road_list'] = $this->urban_circle->get_env_list ( "road", $data ['media_draft_info'] ['region'] );
			$data ['station_list'] = $this->urban_circle->get_env_list ( "station", $data ['media_draft_info'] ['region'] );
			$data ['market_list'] = $this->urban_circle->get_env_list ( "market", $data ['media_draft_info'] ['region'] );
			$data ['stop_list'] = $this->urban_circle->get_env_list ( "stop", $data ['media_draft_info'] ['region'] );
			$data ['venues_list'] = $this->urban_circle->get_env_list ( "venues", $data ['media_draft_info'] ['region'] );
			
			$data ['cbd_list'] = $this->urban_circle->get_env_list ( "cbd", $data ['media_draft_info'] ['region'] );
			$data ['chief_district_list'] = $this->urban_circle->get_env_list ( "chief_district", $data ['media_draft_info'] ['region'] );
			$data ['industrial_list'] = $this->urban_circle->get_env_list ( "industrial", $data ['media_draft_info'] ['region'] );
		}
		$this->load->library ( "media/media_draft_log" );
		$data ['logs'] = $this->media_draft_log->get_logs ( $media_draft_id );
		$this->load->view ( "media/media/get_media_draft", $data );
	}
	public function query_media() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "query_media" )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$this->load->library ( "media/media" );
		$media_id = $this->input->get ( "media_id" );
		$data ['media_info'] = $this->media->query_media_detail ( $media_id );
		
		if (! $data ['media_info']) {
			$data ['title'] = "查看媒体失败";
			$data ['message'] = "没有找到你要查看的媒体信息。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$data ['media_pic_list'] = $this->media->query_media_pic_list ( $media_id );
		
		if ($data ['media_info'] ['media_type'] == "airport") {
			// 获取机场
			$this->load->library ( "env/env_airport" );
			$data ['airport_list'] = $this->env_airport->get_all_airport ();
		} elseif ($data ['media_info'] ['media_type'] == "highway") {
			$this->load->library ( "env/env_highway" );
			$data ['highway_list'] = $this->env_highway->get_all_highway ();
			
			$this->load->library ( "env/highway_section" );
			$data ['section_list'] = $this->highway_section->get_all_section ( $data ['media_info'] ['highway_id'] );
			
			$this->load->library ( "env/highway_point" );
			$data ['point_list'] = $this->highway_point->get_all_point ( $data ['media_info'] ['section_id'] );
		} else {
			$data ['env_list'] = $this->media->query_media_env_list ( $media_id );
			$this->load->library ( "env/urban_circle" );
			$data ['circle_list'] = $this->urban_circle->get_env_list ( "circle", $data ['media_info'] ['region'] );
			$data ['road_list'] = $this->urban_circle->get_env_list ( "road", $data ['media_info'] ['region'] );
			$data ['station_list'] = $this->urban_circle->get_env_list ( "station", $data ['media_info'] ['region'] );
			$data ['market_list'] = $this->urban_circle->get_env_list ( "market", $data ['media_info'] ['region'] );
			$data ['stop_list'] = $this->urban_circle->get_env_list ( "stop", $data ['media_info'] ['region'] );
			$data ['venues_list'] = $this->urban_circle->get_env_list ( "venues", $data ['media_info'] ['region'] );
			$data ['cbd_list'] = $this->urban_circle->get_env_list ( "cbd", $data ['media_info'] ['region'] );
			$data ['chief_district_list'] = $this->urban_circle->get_env_list ( "chief_district", $data ['media_info'] ['region'] );
			$data ['industrial_list'] = $this->urban_circle->get_env_list ( "industrial", $data ['media_info'] ['region'] );
		}
		
		$this->load->view ( "media/media/query_media", $data );
	}
	public function search_media() {
		$user_name = $_SESSION ['user_name'];
		$user_id = $_SESSION ['user_id'];
		$keyword = $this->input->get_post ( "q" );
		$this->load->library ( "media/media" );
		$data ['media'] = $this->media->search_my_media_list ( $user_name, $user_id, $keyword );
		$this->load->helper ( "common" );
		echo JSON ( $data );
	}
	public function import() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "add_media_draft", $_SESSION ['user_id'] )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		
		$data ['media_type'] = $this->input->get ( "media_type" );
		$this->load->view ( "media/media/import", $data );
	}
	public function save_import() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "add_media_draft" )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		$media_type = $this->input->post ( "media_type" );
		$this->load->library ( "media/media" );
		$result =$this->media->import_media_draft ( $media_type );
		if ($result['result']==false) {
			$data ['title'] = "导入失败";
			$data ['message'] = $result['message'];
			$this->load->view ( "common/error_tip", $data );
			return;
		}else{
			$data ['title'] = "导入成功";
			$data ['message'] = $result['message'];
			$data ['back_url'] = base_url()."index.php/media_media_manage";
			$this->load->view ( "common/success_tip", $data );
			return;
		}
	}
}
?>